package com.sample.kokou;

import java.sql.SQLException;

import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.table.TableUtils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class SampleDBHelper extends OrmLiteSqliteOpenHelper {
    private static final String DB_NAME = "test.db";
    private static final int DB_VERSION = 1;

    public SampleDBHelper(Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db, ConnectionSource source) {
        Log.d("CREATE TABLE","new table...");
        try {
            TableUtils.createTable(source, Person.class);

            Dao<Person, Integer> dao = getDao(Person.class);
            dao.create(new Person("山田 浩一郎", 25));
            dao.create(new Person("佐久間 慎吾", 37));
            dao.create(new Person("天城 京子", 18));
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, ConnectionSource source, int oldVersion, int newVersion) {
    }

}
